This script takes the clean SV data and calculates the individual probability of the BV being cast on the issue it was cast on. 

The following rules are tested:

- P_Max: Cast BV on issue with max points 
- P_Sal: Cast BV the most salient election (i.e. Immigration).
- P_Educ: Cast a BV on the education-related proposal with most points (Teachers or Bilingual)
- P_Rand: Cast a BV randomly. Expressed tacitly as P_Rand = 1 - [P_Max + P_Sal + P_Educ]

Method:

- Read in California_MTurk_SV_Stage_2_clean&Recoded_AllPos.csv
- We bootstrap a new sample (with replacement) 10000 times and calculate the estimated probabilities  - where the first iteration corresponds to the parameters using the original data - such that we end up with 10001 estimates.
- Once a new sample is bootstrapped, the code calculates the max points assigned to 1) all referenda and 2) the education referenda. 
- Note that the code will iterate over SV1 and SV2 but the procedure is identical in both cases. 
- For each row, i.e., each subject, it determines how many issues out of all four tied for the max points (saved as MaxPointCount). Similarly, it calculates how many issues tied for just the education max points (saved as EducMaxPointCount).  
- Then, it determines if the vote was cast on immigration and codes (assigns zero or one where the former is given whenever the BV was not cast on immigration) this to be counted for P_Sal if it was the case.
- To calculate P_Max it determines if the BV was cast on an issue that received the most number of points and assigns the cell corresponding to P_Max for that subject a value of 1/MaxPointCount if that was the case and zero otherwise. 
- Lastly to calculate P_Educ it determines if the BV was cast on an education issue that received the most number of points and assigns the cell corresponding to P_Educ for that subject a value of 1/EducMaxPointCount if that was the case and zero otherwise.  
- The per subject log likelihood is: log(data_pmax[item]*Pmax + data_psal[item]*Psal + data_peduc[item]*Peduc + .25*(1 - Pmax - Psal - Peduc)), where data_pname[item] corresponds to the value calculated for each subjects (e.g., data_psal[1] has a value of 1 is the subject cast a BV on imm and zero otherwise as described above). The log likelihood of the dataset is just the sum of the individual log likelihoods.    
- Starting parameters for optimization algorithm are Pmax = .6, P_Sal = .15, P_Educ = .05)
- Once all the iterations are complete, results are saved to a dataframe, SV_StratProb_ParamEstimateMLE.csv, and exported to the folder "Misc - SV & QV Descriptive Model Parameter Estimation"
